package org.zhouhe.tag.security;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.zhouhe.util.Constant;

import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings( { "serial", "unchecked" })
public class ByMethod extends BodyTagSupport {
	private String fullPath;
	private List<String> methodList;

	@Override
	public void doInitBody() throws JspException {
		Map<String, Object> sessionMap = ActionContext.getContext().getSession();
		methodList = (List<String>) sessionMap.get(Constant.SESSION_KEY_USER_METHOD_LIST);
	};

	@Override
	public int doStartTag() throws JspException {
		List<String> list = Arrays.asList(getFullPath().replaceAll(" ", "").split(","));
		if (methodList != null && methodList.containsAll(list)) {
			return EVAL_BODY_INCLUDE;
		}
		return SKIP_BODY;
	}

	public void setFullPath(String fullPath) {
		this.fullPath = fullPath;
	}

	public String getFullPath() {
		return fullPath;
	}

}
